Now let's actually buy a lot.
So let's look at our lots collection.
And we currently have one lot.
I'm going to go to my sign On the sign I have the buy prompt.
We have to change a few values for action text.
Let's call this buy property and then we want it to we want to have the whole duration more than zero
seconds.
Because if they change their mind, we want to give them a chance to release the hold button.
There we go.
Now, when you walk up, you'll get a prompt that'll say buy property.
You have to hold it for three seconds before the sale to come through.
Let's go up to our buy script right underneath the player lot.
Open up the buy script.
GEtrillionID of the print statement.
We're going to need some variables, so I'm going to do one for the lot model lot model.
That's the player lot.
So it's just going to be script dot parent.
I'm going to get a variable for this sign part right here because I'm going to want the buy prompt and
I'm going to want that text label.
So the sign is a good one to make a variable for.
We'll do lot model and then for sale sign sign, that'll get us a lot closer to it.
Then when I do my prompt I'll do sign and I got a buy prompt there.
We're also going to need our property manager, so let's do Prop MGR.
We're going to require that and that's a game server script Service Property Manager.
There we go.
Make a space in there.
Oh, let's get a price.
That's on the lot.
Model price.
And we need the owner.
Oops.
Owner lot, model owner.
Now, when the player walks up, clicks the proximity prompt, he's going to trigger a prompt event.
So we're going to get the prompt and the event is named triggered.
So when it's triggered, we will connect to a function.
The player who triggered the prompt will get passed into the function.
Let's check to see if the player leader stats points dot value is greater than or equal to the price
dot value of the lot.
If it is, then we're going to do another check.
We're going to check if not, prop manager is player lot owner.
So right now we can only buy one lot.
So we're checking to see if he's a lot owner pass in the player.
That's going to be a true or false.
Let me just adjust this explorer and properties so we have a little more room.
So we get here, we have enough points and we don't already own a lot or the player doesn't already
own a lot.
We are going to subtract from the player's leader stats the number of points for the property.
So we'll do a negative equals which will subtract the number of points using price dot value.
Then we got to talk to our data manager, right?
And that's our property manager.
Property manager talks to the data store and we are going to add item to player's inventory.
We have not finished that function though.
We got to go back there and we have to add one line of code to make that work.
We are going to pass in the player.
We're going to pass in a key value.
The key will be has lot and the value will be true.
Oh, didn't quite make it.
There we go.
And what else?
We need to change the owner tag.
We have owner dot value, and that's going to be the player that owns the lot.
Let me just go ahead and move that up.
We're going to need the sign changed.
I can't say for sale.
Somebody owns it.
So we'll say sign surface DUI, text label.
Change the text to the player name player, dot name.
And then let's turn the prompt off so that nobody can nobody thinks they can buy it because we already
own it.
So we'll say prompt dot enabled equals false.
All right.
So that's buying the property.
Let's go over to add item to players inventory.
I am going to right click go to declaration.
We're in the property manager and here is the ADD item to players inventory down here we want to add.
To the property table for the player, a key that equals our value.
Right.
So this is has a lot and that's going to be true.
Then it's going to be in the property table.
Now let's go back to our buy script and we have to account for leaving the game.
I'm going to free up the property right here in the buy script, so I'll just do a game.
Dot players, player service dot player removing connect to an anonymous function player gets passed
in.
We're going to check to see if the player that's leaving is actually the owner of this lot.
If they are, we need to grab these three lines of code.
And set it back.
We have to free our lot, so we're going to free it by making that no, no property owner.
And then this one we can say for sale again.
For sale.
I know that's using a string literal.
That's not that good.
And down here, prompt enabled is now true.
Take a look at these three lines of code.
Notice there's a pattern here.
So whenever we're removing a player or we're making a purchase and also when we enter the game, if
we own property, we have to change this, this and this.
That is ripe for its own function in the property manager up here.
We still we do it when we buy it, right?
We assign the owner, we change the text in the sign and we enable we turn the prompt off.
We disable the prompt if we go to our property manager, right?
It's in server script service.
If you lost it, I have it open.
If I go down to equip player, look at that.
I forgot the prompt.
So I have my owner being assigned.
That's good.
The sign text is being changed.
That's good.
We need to disable the prompt because we're assigning the property to the player.
So do V.
We got the for sale sign for sale sign.
So on the sign I forget.
By prompt.
I know that's all smooshed there, but I remember it now by prompt.
And then that has a property called enabled and we're going to set that to false because we assign the
property to somebody.
We don't want people trying to buy it with the prompt popping up.
All right.
The next video, I'm going to do some print statements.
We're going to do some testing and see if this works.